package com.cater.sys.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cater.annotation.SystemServiceLog;
import com.cater.common.PageResult;
import com.cater.query.LogQuery;
import com.cater.sys.dao.LogDao;
import com.cater.sys.entity.Log;

@Service("logService")
public class LogService {

	@Autowired
	private LogDao logMapper;

	/*
	 * 新增
	 */
	@SystemServiceLog(description = "添加日志文件")    
	public int save(Log log) {
		return logMapper.save(log);
	}
	
	@SystemServiceLog(description = "查询日志")    
	public PageResult<Log> findPageResult(LogQuery logQuery) {
		PageResult<Log> result = new PageResult<Log>();
		result.setPage(logQuery.getPage());
		result.setPageSize(logQuery.getRows());
		int count = logMapper.findCount(logQuery);
		if (count == 0) {
			return result;
		}
		int first = (logQuery.getPage() - 1) * logQuery.getRows();
		int max = logQuery.getRows();
		List<Log> list = logMapper.findList(logQuery, first, max);
		result.setRows(list);
		result.setRecords(count);
		return result;
	}

	
}
